package com.hswealth.demo;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Random;

import javax.imageio.ImageIO;

public class imageCode {
	
	static String[] strs = {"a","b","c","d","e","f","g","h","i","j",
			"k","m","n","p","q","r","s","t","u","v","w","x","y","z","2",
			"3","4","5","6","7","8","9"};
	
	public static void main(String[] args) {
		
		BufferedImage image = new BufferedImage(125, 50, 1);
		
		Graphics graphics = image.getGraphics();
		graphics.setColor(Color.green);
		graphics.fillRect(0, 0, 125, 50);
		
		graphics.setColor(Color.black);
		graphics.setFont(new Font("楷体", Font.BOLD, 25));
		Random random = new Random();
		for (int i = 0; i < 4; i++) {
			int num = random.nextInt(32);
			String str = strs[num];
			graphics.drawString(str, 25+i*25, 30);
		}
		
		graphics.setColor(Color.gray);
		for (int i = 0; i < 10; i++) {
			int x1 = random.nextInt(25);
			int y1 = random.nextInt(50);
			int x2 = random.nextInt(25) + 100;
			int y2 = random.nextInt(50);
			graphics.drawLine(x1, y1, x2, y2);
		}
		
		
		
		try {
			ImageIO.write(image, "jpg", new File("E:\\git\\exercise\\dish system\\imageVerify\\src\\com\\hswealth\\img\\verify.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}
